define(["jQuery", "kendo"], function ($, kendo) {
    return {
    	creationMode:false,
		isGrid: 0,
		heightGrid : 0,
		widthGrid : 0,
		isDashed : 0,
		show : function(){
			if(App.propertyToolbox.isGrid)
			{
				$('#checkbox-grid').prop('checked', true);
			}
			else
			{
				$('#checkbox-grid').prop('checked', false);
			}
			if(App.propertyToolbox.isDashed)
			{
				$('#checkbox-dashed').prop('checked', true);
			}
			else
			{
				$('#checkbox-dashed').prop('checked', false);
			}
			if(App.propertyToolbox.heightGrid <=10)
			{
				$("#pixelGrid").val('20');
			}
			else if(App.propertyToolbox.heightGrid <=20)
			{
				$("#pixelGrid").val('40');
			}
			else if(App.propertyToolbox.heightGrid <=40)
			{
				$("#pixelGrid").val('80');
			}
			$( "#property-dragable-menu" ).show();			
		},
		
        init: function (e) {
			$("#property-dragable-menu").draggable();
			$("#property-dragable-menu").hide(); 
			
			$('.property-tools').live('click', function(data){
				App.propertyToolbox.show();		
			});
			
			
			
			
			$("#button-reset-background").click(function() {
				App.clearBackground();
			});
			
			
			
			
			$(".ok-property-button").click(function() {
				$( "#property-dragable-menu" ).hide();
				
				var checkboxVal = false;
				if ($("#checkbox-grid").attr("checked")) {
					checkboxVal = 1;
				}
				else{
					checkboxVal = 0;				
				}
				App.propertyToolbox.isGrid = checkboxVal;
				
				
				if(App.propertyToolbox.isGrid == 0)
				{
					 $("#rootContainer").destroyGrid();
					 $("#checkbox-grid").val('');
					 
					$('#rootContainer').css('background-image', 'url(' + App.baseUrl+'documents/'+App.fileId+'/background-'+ App.pageId +'.png?ts='+(new Date).getTime()+' )');
					$('#rootContainer').css('background-size', '100%');
				}
				else if(App.propertyToolbox.isGrid == 1)
				{
					
					var checkboxValDashed = false;
					if ($("#checkbox-dashed").attr("checked")) {
						checkboxValDashed = 1;
						
					}
					else{
						checkboxValDashed = 0;		
						
					}
					App.propertyToolbox.isDashed = checkboxValDashed;
					$("#rootContainer").destroyGrid();
					App.propertyToolbox.heightGrid = parseInt($('#pixelGrid').val())/2;
					App.propertyToolbox.widthGrid = parseInt($('#pixelGrid').val())/2;
					
					var base64_string = false;
					var strBckSize = parseInt($('#pixelGrid').val()) + 'px';
					// strBckSize = strBckSize + ' ' + parseInt($('#textbox-width-grid').val()) + 'px';
					if(App.propertyToolbox.isDashed == 1)
					{
						
						if($('#pixelGrid').val() == '20'){
							//20px
							base64_string = 'url()';
						}else if($('#pixelGrid').val() == '40'){
							//40px
							base64_string = 'url()';
						}else if($('#pixelGrid').val() == '80'){
							//80px
							base64_string = 'url()';
						}
						$("#rootContainer").css('background-image', base64_string);
						$("#rootContainer").css('background-repeat', 'repeat repeat');
						$("#rootContainer").css('background-size', strBckSize);
					}
					else
					{
						
						if($('#pixelGrid').val() == '20'){
							//20px
							base64_string = 'url()';
						}else if($('#pixelGrid').val() == '40'){
							//40px
							base64_string = 'url()';
						}else if($('#pixelGrid').val() == '80'){
							//80px
							base64_string = 'url()';
						}
						$("#rootContainer").css('background-image', base64_string );
						$("#rootContainer").css('background-repeat', 'repeat repeat');
						$("#rootContainer").css('background-size', strBckSize);
					} 
					
				}
				
			});
			
			$(".cancel-property-button").click(function() {
				var r=confirm(App.localize("%cancel_confirmation"));
				if (r==true)
				{
					$( "#property-dragable-menu" ).hide();
				}	
			});	

			
			function buildGrid(rowHeight, colWidth) {
				var numRows = Math.floor((window.innerHeight || $('#rootContainer').offsetHeight) / rowHeight);
				var numCols = Math.floor((window.innerWidth || $('#rootContainer').offsetWidth) / colWidth);
				
				 // numCols = numCols ;
				 // numRows = numRows ;
				
				var parent = document.createElement('div');
				parent.className = 'grid';
				// parent.style.height = (numRows * rowHeight) + 'px';
				// parent.style.width = (numCols * colWidth) + 'px';
				parent.style.height = 600 + 'px';
				parent.style.width = 970 + 'px';
				parent.style.top = 0 + 'px';
				parent.style.left = 0 + 'px';
				
				
				for(var row = 0; row < numRows; row++) {
					for(var col = 0; col < numCols; col++) {
						var cell = document.createElement('div');
						cell.className = 'cell';
						cell.style.height = rowHeight + 'px';
						cell.style.width = colWidth + 'px';
						// cell.style.height = numRows + 'px';
						// cell.style.width = numCols + 'px';
						parent.appendChild(cell);
					}
				}
										   
				$('#rootContainer').append(parent);
				// parent.appendTo($('#rootContainer'));
			}
		
		}
	}
});